layui.use('upload', function(){
  var upload = layui.upload;

  upload.render({
    elem: '#combineTxtUpload' //绑定元素
	,auto: false //选择文件后不自动上传
	,accept: 'file'
	,acceptMime: 'text/plain'
    ,choose: function(obj){
    	
        obj.preview(function(index, file, result){
        	result = result.replace('data:text/plain;base64,', '');
        	$('#combineTxt').val(window.atob(result));
        	
        	$("#combineTxt").setTextareaCount({
        		width: "30px",
        		bgColor: "#000",
        		color: "#FFF",
        		display: "inline-block"
        	});
        });
        
      }
  });
  
  upload.render({
	    elem: '#combineListTxtUpload' //绑定元素
		,auto: false //选择文件后不自动上传
		,accept: 'file'
		,acceptMime: 'text/plain'
	    ,choose: function(obj){
	    	
	        obj.preview(function(index, file, result){
	        	result = result.replace('data:text/plain;base64,', '');
	        	$('#combineListTxt').val(window.atob(result));
	        	
	        	$("#combineListTxt").setTextareaCount({
	        		width: "30px",
	        		bgColor: "#000",
	        		color: "#FFF",
	        		display: "inline-block"
	        	});
	        });
	        
	      }
	  });
  
  upload.render({
	    elem: '#combine_motherTxtUpload' //绑定元素
		,auto: false //选择文件后不自动上传
		,accept: 'file'
		,acceptMime: 'text/plain'
	    ,choose: function(obj){
	    	
	        obj.preview(function(index, file, result){
	        	result = result.replace('data:text/plain;base64,', '');
	        	$('#combine_motherTxt').val(window.atob(result));
	        	
	        	$("#combine_motherTxt").setTextareaCount({
	        		width: "30px",
	        		bgColor: "#000",
	        		color: "#FFF",
	        		display: "inline-block"
	        	});
	        });
	        
	      }
	  });
  
  upload.render({
	    elem: '#versionTxtUpload' //绑定元素
		,auto: false //选择文件后不自动上传
		,accept: 'file'
		,acceptMime: 'text/plain'
	    ,choose: function(obj){
	    	
	        obj.preview(function(index, file, result){
	        	result = result.replace('data:text/plain;base64,', '');
	        	$('#versionTxt').val(window.atob(result));
	        	
	        	$("#versionTxt").setTextareaCount({
	        		width: "30px",
	        		bgColor: "#000",
	        		color: "#FFF",
	        		display: "inline-block"
	        	});
	        });
	        
	      }
	  });
});

$('#gameId').select2({
	  placeholder : "请选择游戏",
	  ajax: {
	    url: CONTEXT_PATH + '/game/game/queryAll',
	    dataType: 'json',
	    
	    processResults: function (data) {
	        return {
	        	results: data.data
	        };
	      }
	  },
	  width: '100px'
});

$('#btn_combine_submit').click(function () {
    $("#combine_form").submit();
});

$("#combine_form").validate({
    rules: {
    	gameId : {
    		required: true
    	},
    	combineTxt: {
            required: true
        },
        combineListTxt: {
            required: true
        },
        combine_motherTxt: {
            required: true
        },
        versionTxt: {
            required: true
        },
    },
    messages: {
    	gameId: "请选择游戏",
    	combineTxt: "请填写combine.txt的内容",
    	combineListTxt: "请填写combineList.txt的内容",
    	combine_motherTxt: "请填写combine_mother.txt的内容",
    	versionTxt: "请填写version.txt的内容",
    },
    errorElement: "span",
    submitHandler: function(form) {
    	// 发起合服请求
		var url = CONTEXT_PATH + '/game/combine/combine';
		
		$.wajax({
            type: "POST",
            url: url,
            data: $(form).serialize(),
            success: function(result) {
            	if (result.code == RESULT_FAIL){
            		layer.msg(result.msg);
            	} else {
            		parent.makeGlobalTimerLayer('正在合服', 'combine_timer', 'combine_div_id', result.data);
            	}
            }
        });
    }
});//End